
/**
 * @apiDefine ErrorResponse
 * @apiError (请求错误) {String} err_message 错误信息描述
 */

/**
 * @apiVersion 1.0.0
 * @apiGroup  分类
 * @api {POST} api/category/update 更新分类
 * @apiName api/category/update
 * @apiExample {js} axios 例子:
 *  axios.post('http://39.105.38.34:8080/api/category/update', {
 *    id: '分类id',
 *    name: '分类名'
 *  });
 * @apiHeader {String} authorization 用户登录或注册成功时返回的 token
 * @apiParam {number} id 分类id
 * @apiParam {String} name 分类名
 * @apiSuccess (请求成功) {Object} category 店铺数据
 * @apiuse  ErrorResponse
 */

const { update } = require('../../helper/db');
const { ok, door } = require('../../helper/util');

module.exports = async ctx => {
  var params = ctx.request.body;
  var token = ctx.headers.authorization;
  await door(token);
  var category = await update('category', {
    id: params.id,
    name: params.name
  });

  ctx.body = ok({ category });
}